import { asyncRoutes, constantRoutes } from '@/router'
// 1.准备vuex的模块
export default {
  namespaced: true,
  state: {
    // 路由配置
    routes: constantRoutes
  },
  mutations: {
    setRoutes(state, filterRouter) {
      state.routes = [...constantRoutes, ...filterRouter]
    },
    removeRoutes(state) {
      state.routes = constantRoutes
    }
  },
  actions: {
    // 2.定义过滤路由的action
    filterRouter(context, menus) {
      const filterRoutes = asyncRoutes.filter(t => menus.includes(t.children[0].name))
      context.commit('setRoutes', filterRoutes)
      return filterRoutes
    }
  }
}
